/*****************************************************************
Mix3D WebGL Game Engine
Copyright (c) fantasy ( fantasy.x2x@gmail.com )
Listens:
Distributed under the Boost Software License, Version 1.0.
http://www.boost.org/LICENSE_1_0.txt
 ****************************************************************/
/**
 * @Desc    : event
 * @Author  : fantasy(fantasy.x2x@gmail.com)
 */
//////////////////////////////////////////////////////////////////
if(typeof(Mix3D) === 'undefined')
{
  Mix3D = {};
};
(function(Mix3D){
//////////////////////////////////////////////////////////////////
//
//        func bind
//
//////////////////////////////////////////////////////////////////
Mix3D.bind = function( scope, fn ) 
{
	return function () { fn.apply( scope, arguments );};
};
//////////////////////////////////////////////////////////////////
//
//        events
//
//////////////////////////////////////////////////////////////////
Mix3D.Events = function()
{
  this.eventMap = undefined;
};

Mix3D.Events.prototype.constructor = Mix3D.Events;

Mix3D.Events.prototype.fireEvent = function( strEventName, data )
{
  if(this.eventMap && this.eventMap[strEventName])
  {
    var events = this.eventMap[strEventName];
    for(var i=0, len=events.length; i<len; ++i)
    {
      if(events[i] && events[i].call)events[i].call(this,data);
    }
  }
};

Mix3D.Events.prototype.addEventListener = function(eventName, func)
{
  if(!this.eventMap)this.eventMap={};
  if(!this.eventMap[eventName])this.eventMap[eventName] = [];
  this.eventMap[eventName].push(func);
};

Mix3D.Events.prototype.removeEventListener = function(eventName, func)
{
  if(!this.eventMap[eventName])return;
  var idx = this.eventMap[eventName].indexOf(func);
  if(idx !== -1)this.eventMap[eventName].splice(idx,1);
};

//////////////////////////////////////////////////////////////////
})(Mix3D);// end of function(Mix3D)